#-------------------------------------------------------------------------------
# Copyright (c) 2020, Arm Limited. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
#-------------------------------------------------------------------------------

cmake_policy(SET CMP0079 NEW)

if (NOT TFM_PARTITION_INITIAL_ATTESTATION)
    return()
endif()

####################### Non Secure #############################################

add_library(tfm_test_suite_attestation_ns STATIC EXCLUDE_FROM_ALL)

target_sources(tfm_test_suite_attestation_ns
    PRIVATE
        attest_public_key.c
        attest_token_test.c
        attest_token_decode_common.c
        $<$<BOOL:${SYMMETRIC_INITIAL_ATTESTATION}>:attest_token_decode_symmetric.c>
        $<$<BOOL:${SYMMETRIC_INITIAL_ATTESTATION}>:non_secure/attest_symmetric_ns_interface_testsuite.c>
        $<$<NOT:$<BOOL:${SYMMETRIC_INITIAL_ATTESTATION}>>:attest_token_decode_asymmetric.c>
        $<$<NOT:$<BOOL:${SYMMETRIC_INITIAL_ATTESTATION}>>:non_secure/attest_asymmetric_ns_interface_testsuite.c>
)

target_include_directories(tfm_test_suite_attestation_ns
    PUBLIC
        non_secure
    PRIVATE
        .
)

target_compile_definitions(tfm_test_suite_attestation_ns
    PRIVATE
        DOMAIN_NS=1
        $<$<CONFIG:Debug>:INCLUDE_TEST_CODE>
        $<$<BOOL:${SYMMETRIC_INITIAL_ATTESTATION}>:SYMMETRIC_INITIAL_ATTESTATION>
)

target_link_libraries(tfm_test_suite_attestation_ns
    PRIVATE
        tfm_qcbor
        tfm_t_cose
        tfm_test_framework
        #TODO I'm not sure this should _really_ be linked here
        tfm_attestation_defs
        tfm_boot_status
        platform_ns
)

target_link_libraries(tfm_ns_tests
    INTERFACE
        tfm_test_suite_attestation_ns
)

####################### Secure #################################################

if (TEST_S)
    target_sources(tfm_test_suite_attestation_s
        PRIVATE
            ${CMAKE_CURRENT_SOURCE_DIR}/attest_public_key.c
            ${CMAKE_CURRENT_SOURCE_DIR}/attest_token_test.c
            ${CMAKE_CURRENT_SOURCE_DIR}/attest_token_decode_common.c
            $<$<BOOL:${SYMMETRIC_INITIAL_ATTESTATION}>:${CMAKE_CURRENT_SOURCE_DIR}/attest_token_decode_symmetric.c>
            $<$<BOOL:${SYMMETRIC_INITIAL_ATTESTATION}>:${CMAKE_CURRENT_SOURCE_DIR}/secure/attest_symmetric_s_interface_testsuite.c>
            $<$<NOT:$<BOOL:${SYMMETRIC_INITIAL_ATTESTATION}>>:${CMAKE_CURRENT_SOURCE_DIR}/attest_token_decode_asymmetric.c>
            $<$<NOT:$<BOOL:${SYMMETRIC_INITIAL_ATTESTATION}>>:${CMAKE_CURRENT_SOURCE_DIR}/secure/attest_asymmetric_s_interface_testsuite.c>
    )

    target_include_directories(tfm_test_suite_attestation_s
        PUBLIC
            ${CMAKE_CURRENT_SOURCE_DIR}/secure
        PRIVATE
            ${CMAKE_CURRENT_SOURCE_DIR}
    )

    target_compile_definitions(tfm_test_suite_attestation_s
        PRIVATE
            $<$<CONFIG:Debug>:INCLUDE_TEST_CODE>
            $<$<BOOL:${SYMMETRIC_INITIAL_ATTESTATION}>:SYMMETRIC_INITIAL_ATTESTATION>
    )

    target_link_libraries(tfm_test_suite_attestation_s
        PRIVATE
            tfm_qcbor
            tfm_t_cose
            tfm_test_framework
            tfm_partition_attestation
            tfm_boot_status
            tfm_partition_crypto
            platform_s
    )

    target_link_libraries(tfm_s_tests
        INTERFACE
            tfm_test_suite_attestation_s
    )
endif()
